package com.example.hotelrear.controller;

<<<<<<< HEAD
import com.example.hotelrear.entity.Config;
import com.example.hotelrear.entity.ResponseResult;
import com.example.hotelrear.service.ConfigService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
=======
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.hotelrear.entity.Config;
import com.example.hotelrear.entity.ResponseResult;
import com.example.hotelrear.service.ConfigService;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.sql.Date;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
>>>>>>> c858df565d55deb60e87bd48c878762d1fd5080a

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author FengXiao
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/config")
@CrossOrigin("*")
public class ConfigController {
    @Resource
    private ConfigService configService;

<<<<<<< HEAD
    @RequestMapping("/findAll")
    public ResponseResult findALl() {
        List<Config> listALl=configService.listAll();
        return ResponseResult.ok(listALl);
    }
=======
    @Autowired
    private ConfigService configService;

    @RequestMapping("/add")
    public void addConfig(Config config) {
        config.setCreateTime(LocalDateTime.now());
        configService.addConfig(config);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteConfig(@PathVariable("id") Long id) {
        configService.deleteConfig(id);
    }

    @PostMapping("/update")
    public boolean updateConfig(Config config) {
        config.setCreateTime(LocalDateTime.now());
        return configService.saveOrUpdate(config);
    }

    @GetMapping("/get/{id}")
    public Config getConfigById(@PathVariable("id") Long id) {
        return configService.getConfigById(id);
    }

    @GetMapping("/get/all")
    public List<Config> getAllConfigs() {
        return configService.getAllConfigs();
    }

    @PostMapping("/batch/delete")
    public int batchDelete(@RequestParam List<Long> ids) {
        return configService.batchDelete(ids);
    }

    @RequestMapping("/select/{id}")
    public ResponseResult page(@PathVariable Integer id){
        IPage<Config> configIPage = configService.selectPage(new Page<>(1,2),id);
        System.out.println("总页数"+configIPage.getPages());
        System.out.println("总记录数"+configIPage.getTotal());
        configIPage.getRecords().forEach(System.out::println);
        return ResponseResult.ok(configIPage);
    }




>>>>>>> c858df565d55deb60e87bd48c878762d1fd5080a
}
